const {personalModel}=require('./models/salespersonsModel');
module.exports.getSalespersons=async function(params){
    const total=await personalModel.countDocuments();
    const pages =Math.ceil(total/params.pageSize);
    const salespersons=await personalModel.find().limit(params.pageSize*1).skip((params.currentPage-1)*params.pageSize);
    console.log('Dao',params);
    return {total,pages,salespersons}
};
module.exports.searchPersonal=async (params)=>{
   
    const total=await personalModel.countDocuments({names:{$regex:params.value,$options:'$i'}});
    const pages =Math.ceil(total/params.pageSize);
    const salespersons= await personalModel.find({names:{$regex:params.value,$options:'$i'}}).limit(params.pageSize*1).skip((params.currentPage-1)*params.pageSize);
    
    return{total,pages,salespersons}
 };
 module.exports.getSalespersonsById=async function(params){
    return await personalModel.find({_id:params})
};
module.exports.updateSalespersons=async params=>{
    
    return await personalModel.updateOne({_id:params.personalData._id},params.personalData);
    
 };
 module.exports.deleteSalespersons=async params=>{
    return await personalModel.deleteOne({_id:params.salespersonsId});
 };
 module.exports.addSalespersons=async params=>{
    return await personalModel.create(params);
 };
